package com.mcxx.modules.report.service.impl;

import com.mcxx.common.ReportExtendUtils;
import com.mcxx.modules.report.service.StatisDataService;
import com.mcxx.modules.statistics.entity.StatisDataItemEntity;
import com.mcxx.modules.statistics.entity.StatisItemEntity;
import com.yinhai.ta404.component.org.orguser.area.entity.TaAreaPo;
import com.yinhai.ta404.core.transaction.annotation.TaTransactional;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service
@TaTransactional
public class PovertyCountryCompService extends StatisDataService {
    @Override
    public String getAccumulativeGoalCode(String basicCode) {
        if (basicCode.equals("countyNewTimes"))
            return "countyTimes";
        else if(basicCode.equals("countyNewFundPay"))
            return "countyFundPay";
        else if(basicCode.equals("countyNewSubsidy"))
            return "countySubsidy";
        else if(basicCode.equals("countyNewRepamemt"))
            return "countyRepamemt";
        else if(basicCode.equals("county_newFuneral"))
            return "county_funeralPay";
        return "";
    }

    private final static org.slf4j.Logger logger = LoggerFactory.getLogger(SubCityCompService.class);


    public void generateItemReport(TaAreaPo curTaAreaPo, String month, String itemSetId,
                                   StatisItemEntity item) {

        List<StatisDataItemEntity> paList = new ArrayList<>();

        if ("city_add_second".equals(item.getStatisItemCode())) {

            logger.info("执行指标，name:{}, code:{}", item.getStatisItemName(), item.getStatisItemCode());

            paList = ReportExtendUtils.getResultListNotByDataItem(month, itemSetId, item, curTaAreaPo, super.areaUtil, super.statisDataItemReadDao);
        } else {

            paList = ReportExtendUtils.getStaticsDataItemEntities(curTaAreaPo, month, item,super.areaUtil, super.statisDataItemReadDao);
        }

        Map<String, StatisDataItemEntity> mapSuperLevelSummary = ReportExtendUtils.sumResultBasicData(month, itemSetId, item, paList, super.areaUtil, super.statisDataItemReadDao);


        ReportExtendUtils.clearAndUpdate(mapSuperLevelSummary, paList, curTaAreaPo, month, item.getBusinessType(),
                item.getStatisItemCode(), item.getExceptionalPovertyType(),super.areaUtil, super.statisDataItemReadDao);
    }
}
